#include <iostream>
#include "Thread.hpp"
#include <vector>


using namespace ThreadModule;

#define NUM 4

int ticketnum = 10000;//临界资源

void Ticket()
{
    while(true)
    {
        if(ticketnum > 0)
        {
            usleep(1000);
            //1.抢票
            printf("get a new ticket, id: %d\n",ticketnum--);            
        }
        else
        {
            break;
        }
    }
}

int main()
{
    //1.构建线程对象
    std::vector<Thread> threads;
    for(int i = 0;i < NUM;i++)
    {
        threads.emplace_back(Ticket);
    }

    //2.启动线程
    for(auto& thread:threads)
    {
        thread.Start();
    }

    //3.等待线程
    for(auto& thread:threads)
    {
        thread.Join();
    }
    return 0;
}

